package addition_fr;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Question implements IQuestion {

    protected int numQuestion = 0;
    protected String question = null;
    protected Set<IReponseScore> reponsesScores = null;

    public Question(int numQuestion, String question) {
        this(numQuestion, question, new HashSet<IReponseScore>());
    }

    public Question(int numQuestion, String question, Set<IReponseScore> reponsesScores) {
        this.numQuestion = numQuestion;
        this.question = question;
        this.reponsesScores = reponsesScores;
    }

    @Override
    public void addReponseScore(String reponse, int score) {
        IReponseScore reponseScore = new ReponseScore(reponse, score);
        reponsesScores.add(reponseScore);
    }

    @Override
    public void addReponseScoreAdditionnelle(String questionAdditionnelle, String reponse, int score) {
        IReponseScore reponseScoreAdditionnelle = new ReponseScoreAdditionnelle(questionAdditionnelle, reponse, score);
        reponsesScores.add(reponseScoreAdditionnelle);
    }

    @Override
    public IReponseScore find(String reponse) {
        Iterator<IReponseScore> itReponsesScores = reponsesScores.iterator();
        IReponseScore currentReponseScore = null;
        while (itReponsesScores.hasNext()) {
            currentReponseScore = itReponsesScores.next();
            if (currentReponseScore.getReponse().equals(reponse)) {
                return currentReponseScore;
            }
        }
        return null;
    }

    @Override
    public int getNumQuestion() {
        return numQuestion;
    }
}
